﻿@using Badge = Passwordless.AdminConsole.Components.Shared.Badge

@inject NavigationManager NavigationManager
@inject ICurrentContext CurrentContext
@inject IHttpContextAccessor HttpContextAccessor

<nav class="space-y-1 flex flex-col h-full content-between overflow-y-auto">
    <CascadingAuthenticationState>
        <AuthorizeView>
            <Authorized>
                <div class="sidebar-content">
                    <NavMenuItem Href="@OrganizationOverviewUrl" Icon="@typeof(CodeBracketSquareIcon)" Label="Applications" />
                    <ApplicationNavMenu />
                    <NavMenuItem Href="/billing/default" Icon="@typeof(DollarIcon)" Label="Billing" />
                    @if (HttpContextAccessor.HttpContext!.Request.Path.StartsWithSegments("/billing"))
                    {
                        <div class="nav-link-submenu">
                            <NavMenuItem Href="/billing/manage" Icon="@typeof(CogIcon)" Label="Manage" />
                            <NavMenuItem Href="/billing/invoices" Icon="@typeof(DocumentTextIcon)" Label="Invoices" />
                        </div>
                    }
                    <NavMenuItem Href="/organization/admins" Icon="@typeof(UsersIcon)" Label="Admins" />
                    <NavMenuItem Href="/organization/settings" Icon="@typeof(CogIcon)" Label="Settings" />
                    @if (CurrentContext.OrganizationFeatures.EventLoggingIsEnabled)
                    {
                        <NavMenuItem Href="/organization/log" Icon="@typeof(CodeBracketSquareIcon)" Label="Organization Logs" />
                    }
                </div>
                <div class="sidebar-footer">
                    @if (!CurrentContext.Organization!.HasSubscription)
                    {
                        <NavLink href="/billing/manage" class="block">
                            <Badge Variant="ContextualStyles.Warning" Message="Free organization"></Badge>
                        </NavLink>
                    }
                    <div class="space-y-2">
                        <NavLink class="text-sm font-medium text-white truncate flex" href="/account/profile">
                            <CogIcon Class="w-5 h-5 mr-2"/>
                            <span class="truncate">
                                @context.User.Identity!.Name
                            </span>
                        </NavLink>
                    </div>
                    <hr class="opacity-30"/>
                    <div class="flex flex-row space-x-4">
                        <a class="text-white flex font-medium text-sm" href="/account/logout">Sign out</a>
                    </div>
                </div>
            </Authorized>
            <NotAuthorized>
                <!-- Empty -->
            </NotAuthorized>
        </AuthorizeView>
    </CascadingAuthenticationState>
</nav>

@code {
    public const string OrganizationOverviewUrl = "/organization/overview";
}